Skip to content

Conversation

mathause
Copy link
Contributor

Adds a clearer error message a package is missing a version in the environment file (and is not in exclude. Currently raises AttributeError: 'NoneType' object has no attribute '_version'

Traceback (most recent call last):
  File "/home/runner/work/_actions/xarray-contrib/minimum-dependency-versions/v0.1.1/minimum_versions.py", line 414, in <module>
    main()
  File "/usr/lib/python3/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.local/lib/python3.12/site-packages/rich_click/rich_command.py", line 187, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_actions/xarray-contrib/minimum-dependency-versions/v0.1.1/minimum_versions.py", line 386, in main
    status = compare_versions(environments, policy_versions, policy.ignored_violations)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_actions/xarray-contrib/minimum-dependency-versions/v0.1.1/minimum_versions.py", line 247, in compare_versions
    env_status = any(
                 ^^^^
  File "/home/runner/work/_actions/xarray-contrib/minimum-dependency-versions/v0.1.1/minimum_versions.py", line 250, in <genexpr>
    and spec.version > policy_versions[spec.name].version
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.local/lib/python3.12/site-packages/rattler/version/version.py", line 544, in __lt__
    return self._version < other._version
                           ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_version'

@mathause
Copy link
Contributor Author

Not so sure about the test 🤷‍♂️

Comment on lines +363 to +366
_main(today, policy_file, environment_paths)


def _main(today, policy_file, environment_paths):
Copy link
Member

@keewis keewis Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might need to clean this up a bit: currently _main would call sys.exit, which is not great for testing. It also should take the contents of the files instead of file handles / paths, which avoids the need to do I/O in the tests.

Additionally, _main is not really a descriptive name. How about something like validate_environment instead?

Comment on lines +383 to +384
assert_spec_has_version(environments)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be done at the same time as applying exclude? I don't have the time to come up with something better right now, but assuming this isn't too urgent I will spend some time on this later this week.

@keewis
Copy link
Member

keewis commented Sep 10, 2025

also, does this close #28?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants